﻿// Copyright (c) 2012 - 2020 Jared Zheng <jaredz at outlook dot com>
// Buddha Framework is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
//          http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.
//
// Create : 2012-12-01 version 0.1 Jared Zheng <jaredz at outlook dot com>
// Update : 2018-12-05 version 3.1.5 Jared Zheng <jaredz at outlook dot com>

#ifndef __COMMON_SERVER_H__
#define __COMMON_SERVER_H__

#pragma once

#include "servermap.h"
#include "serversort.h"
#include "ServerConfig.h"

///////////////////////////////////////////////////////////////////////////////////////////////////////////
/// 服务器接口
class NOVTABLE ICommonServer ABSTRACT : public CComponent
{
public:
    /// CComponent
    /// 按配置文件中配置项名称更新相关参数
    //virtual UInt   Command(PCXStr pszCMD, uintptr_t utParam) PURE;
    //virtual UInt   Update(void) PURE;
    /// 初始化服务器
    /// @param[in] CEventHandler& EventHandlerRef事件处理
    /// @return 成功返回RET_OKAY(0)， 非零值表示错误编号
    virtual UInt   Init(CEventHandler& EventHandlerRef, CServerConfig& ConfigRef) PURE;
    /// 结束服务器
    virtual void   Exit(void) PURE;
    /// 开启服务
    virtual bool   Start(void) PURE;
    /// 暂停服务
    /// @param bool bPause 暂停还是继续
    virtual bool   Pause(bool bPause = true) PURE;
    /// 停止服务
    virtual void   Stop(void) PURE;
    /// 例程调用接口
    virtual Socket_t          GetSocket(UInt uType) PURE;
    virtual PSERVER_INFO      GetServerInfo(UInt uType) PURE;
    virtual PSVR_COMMON_MAP   GetServerMap(UInt uType) PURE;
    virtual PRESULT_CHAIN     GetServerSort(UInt uType) PURE;
    virtual CServerConfig&    GetConfig(void) PURE;
    virtual CFileLog&         GetFileLog(void) PURE;
    virtual CEventHandlerPtr& GetMgrHandler(void) PURE;
    virtual CNetworkPtr&      GetNetworkPtr(void) PURE;
};
typedef CTRefCountPtr<ICommonServer> CCommonServerPtr;

///////////////////////////////////////////////////////////////////////////////////////////////////////////
/// CCommonServerSystem : CSubSystem
DECLARE_UUID( CCommonServerSystem, {782B6B51-2686-443d-A575-62199CAF1576} )

#endif // __COMMON_SERVER_H__
